package com.swagger.knife4jdemo.controller;

import com.swagger.knife4jdemo.common.Result;
import com.swagger.knife4jdemo.entity.CityEntity;
import com.swagger.knife4jdemo.service.CityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author 哲思小辉
 * @version 1.0.0
 * @ClassName CityController.java
 * @Description 城市管理控制类
 * @Param
 * @createTime 2020年03月24日 16:49:00
 */
@Component
@RestController
@Api(value = "城市管理控制类", tags = "城市管理控制类")
@Slf4j
public class CityController {

    @Autowired
    private CityService cityService;

    @GetMapping("/getCityList")
    @ApiOperation(value = "getCityList", notes = "获取城市列表")
    @ResponseBody
    public Result<List<CityEntity>> getCityList() {
        return cityService.getCityList();
    }

    @PostMapping("/addCity")
    @ApiOperation(value = "addCity", notes = "新增城市（请求参数校验）")
    @ResponseBody
    public Result<CityEntity> addCity(@RequestBody @Validated CityEntity cityEntity) {
        return cityService.addCity(cityEntity);
    }

    @PostMapping("/addCityByInterface")
    @ApiOperation(value = "addCityByInterface", notes = "新增城市（接口库参数校验）")
    @ResponseBody
    public Result<CityEntity> addCityByInterface(@RequestBody CityEntity cityEntity) {
        return cityService.addCity(cityEntity);
    }


    @DeleteMapping("/deleteCity")
    @ApiOperation(value = "deleteCity", notes = "删除城市")
    @ResponseBody
    public Result deleteCity(@RequestBody @NotNull Long cityId) {
        return cityService.deleteCity(cityId);
    }


}
